package com.sebiotec.manager.ui.activity;

import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.allen.library.RxHttpUtils;
import com.sebiotec.basecommon.utils.base.BaseActivity;
import com.sebiotec.basecommon.utils.entity.CardTypeUtils;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.TimeUtil;
import com.sebiotec.manager.R;
import com.sebiotec.manager.R2;
import com.sebiotec.manager.adapt.MsgAdapt;
import com.sebiotec.manager.model.response.MessageDetailResponse;
import com.sebiotec.manager.viewmodel.BookDetailViewModel;
import com.hedan.textdrawablelibrary.TextViewDrawable;
import com.xuexiang.xui.widget.toast.XToast;

import butterknife.BindView;
import butterknife.OnClick;

public class BookDetailActivity extends BaseActivity {



    @BindView(R2.id.tv_message_passenger)
    TextView tvMessagePassenger;
    @BindView(R2.id.tv_pax_lug)
    TextView tvPaxLug;
    @BindView(R2.id.tv_message_detail_clientid)
    TextView tvMessageDetailClientid;

    @BindView(R2.id.tv_pick_up_date)
    TextView tv_pick_up_date;
    @BindView(R2.id.tv_book_by)
    TextView tv_book_by;
    @BindView(R2.id.iv_back)
    ImageView iv_back;
    @BindView(R2.id.tv_pick_up_time)

    TextView tv_pick_up_time;
    @BindView(R2.id.tv_pick_up_from)
    TextViewDrawable tv_pick_up_from;
    @BindView(R2.id.tv_destination)
    TextViewDrawable tv_destination;
    @BindView(R2.id.tv_charged_type)
     TextView tv_charged_type;
    @BindView(R2.id.tv__type_vehice)
     TextView tv__type_vehice;


    @BindView(R2.id.tv_itinerary)
    TextView tv_itinerary;

    @BindView(R2.id.tv_signboard)
    TextView tv_signboard;
    @BindView(R2.id.tv_remake)
    TextView tv_remake;
    @BindView(R2.id.tv_driver)
    TextView tv_driver;
    @BindView(R2.id.tv_ucs_phone)
    TextView tv_ucs_phone;

    @BindView(R2.id.tv_plate)
    TextView tv_plate;
    @BindView(R2.id.textView8)
    TextView textView8;
    @BindView(R2.id.recy_message_detail)
    RecyclerView recy_message_detail;


    @BindView(R2.id.tv_no_data)
    TextView tv_no_data;



    @BindView(R2.id.tv_go_mark)
    TextView tv_go_mark;
    @BindView(R2.id.iv_mark)
    ImageView iv_mark;
    @BindView(R2.id.tv_card_type)
    TextView tv_card_type;
    @BindView(R2.id.tv_pay_id)
    TextView tv_pay_id;
    @BindView(R2.id.cb_round_trip)
    CheckBox cb_round_trip;
    private BookDetailViewModel messageDetailsViewModel;

    String BookingId;
    @Override
    protected int setLayoutId() {
        return R.layout.man_activity_book_detail1;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RxHttpUtils.cancel("ManagerBookDetail");
    }

    @Override
    protected void initUI() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recy_message_detail.setLayoutManager(linearLayoutManager);

        if (getIntent().hasExtra("BookingId")) {
            BookingId = getIntent().getStringExtra("BookingId");
        }
        messageDetailsViewModel = ViewModelProviders.of(this).get(BookDetailViewModel.class);

    }

    @Override
    protected void initData() {
        messageDetailsViewModel.getData(BookingId, new BookDetailViewModel.MyBookDetailDataCallBack<Object>() {
            @Override
            public void onDataSuccessCallBack(Object o) {

                MessageDetailResponse bean = (MessageDetailResponse) o;
                MessageDetailResponse.BookingBean booking = bean.getBooking();

                if (booking.getBookmark()==1){
                    tv_go_mark.setVisibility(View.GONE);
                    iv_mark.setVisibility(View.VISIBLE);
                }else{
                    tv_go_mark.setVisibility(View.VISIBLE);
                    iv_mark.setVisibility(View.GONE);
                }
                tv_book_by.setText(booking.getCreateUser());
                tvMessagePassenger.setText(booking.getPassengers()+"");
                tvPaxLug.setText(booking.getLug()+"");
                tvMessageDetailClientid.setText(booking.getClientId());
                tv_pick_up_date.setText(TimeUtil.getFormatData_ns(booking.getPickupDateTime()));
                tv_pick_up_time.setText(TimeUtil.getFormatData_m(booking.getPickupDateTime()));
                tv_pick_up_from.setText(booking.getPickupFrom());
                tv_destination.setText(booking.getDestination());
                tv_charged_type.setText(booking.getChargedTypeDescr());
                tv__type_vehice.setText(booking.getVechileTypeDescr());
                textView8.setText(booking.getName());
                tv_signboard.setText(booking.getSignboard());
                tv_remake.setText(booking.getRemark());
                tv_driver.setText(booking.getDriver());
                tv_ucs_phone.setText(booking.getPhone());
                tv_plate.setText(booking.getVehPlate());
                tv_itinerary.setText(booking.getItinerary());
                if (bean.getEvents()!=null&&bean.getEvents().size()>0){
                    tv_no_data.setVisibility(View.GONE);
                    MsgAdapt adapt=new MsgAdapt(R.layout.item_message_detail,bean.getEvents());
                    recy_message_detail.setAdapter(adapt);
                }else{
                    tv_no_data.setVisibility(View.VISIBLE);
                }
                if (bean.getBooking().getRoundTrip()==1){
                    cb_round_trip.setChecked(true);
                    cb_round_trip.setClickable(false);
                }else{
                    cb_round_trip.setChecked(false);
                    cb_round_trip.setClickable(false);
                }
                tv_card_type.setText(CardTypeUtils.Format(booking.getCardType()));
                tv_pay_id.setText(booking.getPaymentID());

            }

            @Override
            public void onDataFailCallBack(Object o) {

            }
        });
    }

    @Override
    protected void setListener() {

    }

    @OnClick({R2.id.iv_back,R2.id.tv_go_mark})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.iv_back) {
            ActivityTool.getInstance().popOneActivity(this);
        }else if (id==R.id.tv_go_mark){
            messageDetailsViewModel.setMark(BookingId, new BookDetailViewModel.MyBookDetailDataCallBack<Object>() {
                @Override
                public void onDataSuccessCallBack(Object o) {
                    XToast.success(BookDetailActivity.this,getString(R.string.bookmark_is_success)).show();
                    tv_go_mark.setVisibility(View.GONE);
                    iv_mark.setVisibility(View.VISIBLE);
                }

                @Override
                public void onDataFailCallBack(Object o) {
                    XToast.error(BookDetailActivity.this,getString(R.string.mark_failed)).show();

                }
            });


        }
    }
}
